<template>
  <div class="login-container">
  <div class="login-page">
    <h2 class="title">欢迎登录</h2>
    <form class="login-form">
      <div class="form-group">
        <label for="username">用户名</label>
        <input type="text" v-model="loginForm.username" id="username" placeholder="请输入用户名" />
      </div>
      <div class="form-group">
        <label for="password">密码</label>
        <input type="password" v-model="loginForm.password" id="password" placeholder="请输入密码" />
      </div>
      <button class="submit-btn" @click.prevent="handleLogin">登录</button>
    </form>
  </div>
  </div>

</template>

<style scoped>
.login-container {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  height: 100vh; /* 使容器高度占满整个视口高度 */
  background-image: url(../assets/images/login-background.jpg);
  background-size: cover;
}
.login-page {
  min-width: 400px;
  margin: 0px auto;
  padding: 20px;
  background-color: #f9f9f9;
  
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.title {
  text-align: center;
  color: #333;
  margin-bottom: 30px;
}

.login-form {
  display: flex;
  flex-direction: column;
}

.form-group {
  margin-bottom: 20px;
  padding: 0 20px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  color: #666;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
}

.submit-btn {
  background-color: #4CAF50;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.submit-btn:hover {
  background-color: #45a049;
}

@media (max-width: 480px) {
  .login-page {
    padding: 15px;
  }

  input[type="text"],
  input[type="password"] {
    font-size: 14px;
  }

  .submit-btn {
    padding: 8px 16px;
  }
}
</style>

<script>
export default {
  name: 'LoginPage',
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      }
    }
  },
methods: {
  async handleLogin() {
    try {
      const { data: res } = await this.$http.post('/login', this.loginForm);
      sessionStorage.setItem('islogin', true);
      this.$router.push('/');
    } catch (error) {
      console.log(error);
      alert('登录失败，请检查用户名和密码！');
    }
    console.log("123", this.loginForm);
  }
}
}
</script>